import cv2
import numpy as np

class ImageTool(object):

    # 移除选择的像素

    def removeImageArea(targetimg,removeCountours):
        """ targetimg 是目标图像 numpy的darray格式 size=n*n  第一维度为N个轮廓  第二维度为每个轮廓的点集合
            removeContours是需要移除的轮廓..
        """
        resultimg=None
        try:
            imgcontour = np.zeros(shape=targetimg.shape, dtype=np.uint8)  # 创建一个空白图
            imgcontour[:] = 255  # 设置为纯白色
            h, w = targetimg.shape[0:2]
            for countourArrayitem in removeCountours:
                countourArrayfloat = np.copy(countourArrayitem)
                countourArrayfloat[:, 0] *= w
                countourArrayfloat[:, 1] *= h
                countourArrayint = np.int32(countourArrayfloat)
                cv2.fillConvexPoly(imgcontour, countourArrayint, (0, 0, 0))
            #移除需要的部分
            resultimg = targetimg & imgcontour
        except Exception as e:
            print(e)
        return resultimg